package oj.swing.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;


public class OJField implements Serializable {
  private String id, idSearch, searchDescription, tablePick, fieldPick;
  private char   visualType;
  private int    length;
  private int  decimalLength;
  private String validationMethod, physicalField, mask, dataType, label;
  private String defaultValue;
  private char   defaultType;
  private String hintCode;
  private boolean notNull, logical, pk;
  private String  pickQuery;
  private HashMap listValues;
  private String  validationFrom, validationTo;
  private char    validationType;
  private char    totalType;
  private boolean uniqueField;
  private String  totalPhysField;
  private String  totalPhysFieldGroup;

  public OJField() {
    init();
  }

  public OJField(String i) {
    init();
    setId(i);
  }

  private void init() {
    id = "";
    length = 0;
    decimalLength = 0;
    visualType = ' ';
    idSearch = "";
    searchDescription = "";
    tablePick = "";
    fieldPick = "";
    pickQuery = "";
    validationMethod = "";
    physicalField = "";
    mask = "";
    dataType = "";
    notNull = false;
    logical = false;
    pk = false;
    listValues = null;
  }

  public void setId(String i) {
    id = i;
  }

  public void setLength(int l) {
    length = l;
  }

  public void setDecimalLength(int dl) {
    decimalLength = dl;
  }
  
  public void setIdSearch(String i) {
    idSearch = i;
  }

  public void setSearchDescription(String sd) {
    searchDescription = sd;
  }

  public void setPickTable(String tPick) {
    if (tPick == null) {
      tablePick = "";
    }
    else {
      tablePick = tPick;
    }
  }

  public void setVisualType(char type) {
    visualType = type;
  }

  public char getVisualType() {
    return visualType;
  }

  public void setPickField(String fPick) {
    if (fPick == null) {
      fieldPick = "";
    }
    else {
      fieldPick = fPick;
    }
  }

  public String getPickTable() {
    return tablePick;
  }

  public String getPickField() {
    return fieldPick;
  }

  public void setValidationMethod(String v) {
    validationMethod = v;
  }

  public void setPhysicalField(String p) {
    physicalField = p;
  }

  public void setMask(String m) {
    mask = m;
  }

  public void setDataType(String d) {
    dataType = d;
  }

  public void setLabel(String l) {
    label = l;
  }

  public void setNotNull(boolean m) {
    notNull = m;
  }

  public void setLogical(boolean l) {
    logical = l;
  }

  public void setPickQuery(String pickQuery) {
    if (pickQuery != null) {
      this.pickQuery = pickQuery;
    }
  }

  public void setListValues(HashMap listValues) {
    this.listValues = listValues;
  }

  public void setDefaultType(char defaultType) {
    this.defaultType = defaultType;
  }

  public void setDefaultValue(String defaultValue) {
    this.defaultValue = defaultValue;
  }

  public void setHintCode(String hintCode) {
    this.hintCode = hintCode;
  }

  public void setValidationFrom(String validationFrom) {
    this.validationFrom = validationFrom;
  }

  public void setValidationType(char validationType) {
    this.validationType = validationType;
  }

  public void setValidationTo(String validationTo) {
    this.validationTo = validationTo;
  }

  public void setTotalPhysFieldGroup(String totalPhysFieldGroup) {
    this.totalPhysFieldGroup = totalPhysFieldGroup;
  }

  public void setTotalPhysField(String totalPhysField) {
    this.totalPhysField = totalPhysField;
  }

  public void setTotalType(char totalType) {
    this.totalType = totalType;
  }

  public void setPrimaryKey(boolean p) {
    pk = p;
  }

  public String getId() {
    return id;
  }

  public int getLength() {
    return length;
  }

  public int getDecimalLength(){
    return decimalLength;
  }  
  
  public String getIdSearch() {
    return idSearch;
  }

  public String getSearchDescription() {
    return searchDescription;
  }

  public String getValidationMethod() {
    return validationMethod;
  }

  public String getPhysicalField() {
    return physicalField;
  }

  public String getMask() {
    return mask;
  }

  public String getDataType() {
    return dataType;
  }

  public boolean isNotNull() {
    return notNull;
  }

  public boolean isLogical() {
    return logical;
  }

  public boolean isPrimaryKey() {
    return pk;
  }

  public String getLabel() {
    return label;
  }

  public String getPickQuery() {
    return pickQuery;
  }

  public HashMap getListValues() {
    return listValues;
  }

  public char getDefaultType() {
    return defaultType;
  }

  public String getDefaultValue() {
    return defaultValue;
  }

  public String getHintCode() {
    return hintCode;
  }

  public String getValidationFrom() {
    return validationFrom;
  }

  public char getValidationType() {
    return validationType;
  }

  public String getValidationTo() {
    return validationTo;
  }

  public String getTotalPhysFieldGroup() {
    return totalPhysFieldGroup;
  }

  public String getTotalPhysField() {
    return totalPhysField;
  }

  public char getTotalType() {
    return totalType;
  }

  public String[] getPickFields() {
    String pick = getPickField();

    ArrayList a = new ArrayList();
    String f = "";
    char[] c;
    c = pick.toCharArray();

    for (int n = 0; n < c.length; n++) {
      String c1 = String.valueOf(c[n]);
      if (c1.equals(",")) {
        a.add(f);
        f = "";
      }
      else {
        if (!c1.equals(" ")) {
          f += c1;
        }
      }
    }

    if (f.length() > 0) {
      a.add(f);
    }

    String[] b = new String[] {};
    b = (String[]) a.toArray(b);
    return b;
  }

  public String getPickEditField() {
    String pick = getPickField();

    String f = "";
    char[] c;
    c = pick.toCharArray();

    for (int n = 0; n < c.length; n++) {
      String c1 = String.valueOf(c[n]);
      if (c1.equals(",")) {
        break;
      }
      else {
        if (!c1.equals(" ")) {
          f += c1;
        }
      }
    }

    return f;
  }

  public boolean isUniqueField() {
    return uniqueField;
  }

  public void setUniqueField(boolean uniqueField) {
    this.uniqueField = uniqueField;
  }
  
}